<template>
  <el-dialog
    custom-class="audit-staff-reim"
    v-el-drag-dialog="{ drag: true, full: true, resize: false }"
    :close-on-click-modal="false"
    :visible="true"
    @close="closeMd"
    width="40%"
    title="审核报账"
    append-to-body>
    <el-form 
      :model="fm.ps" 
      :ref="fm.fname" 
      label-width="120px">
      <el-form-item 
        label="通知人账号" 
        prop="alNoticeChoice"
        :rules="[{ required: true, message: '审核后通知人账号', trigger: 'blur' }]">
        <el-select 
          style="width: 100%" 
          v-model="fm.ps.alNoticeChoice"
          multiple filterable
          placeholder="通知人账号">
          <el-option 
            v-for="item in staffOptions"
            :key="item.baseUserId.uname"
            :label="item.baseUserId.realName"
            :value="item.baseUserId.uname">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="备注" prop="note">
        <el-input v-model="fm.ps.note" />
      </el-form-item>
    </el-form>

    <div class="fm-btn-row">
      <el-button 
        :loading="fm.sb.load" 
        style="margin-left: 20px" 
        type="primary" 
        icon="el-icon-success"
        @click="onSubmit">
        确 定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import elDragDialog from "@/directive/el-drag-dialog";

import * as orderSer from "@/api/services/order.service";
import * as commonSer from "@/api/services/common.service";

export default {
  name: "AuditStaffReim",
  directives: { elDragDialog },
  props: {myData: Object},
  data() {
    return {
      fm: {
        fname: 'auditStaffReimFm',
        sb: {load: false},
        ps: {
          // 审核记录id,多条审核逗号拼接
          ids: '', 
          // 审核后通知人uname，多个通知逗号拼接，可为空
          alNoticeChoice: '', 
          // 审核备注，可为空
          note: '', 
        },
      },

      // 员工账号-列表
      staffOptions: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    closeMd() {
      this.$emit("myClick", {state: false});
    },
    init() {
      // 设置-审核记录id数组字符串
      this.fm.ps.ids = this.myData.list.map(it => it.id).join(',');

      // 获取-员工列表
      commonSer.getStaffCombo({isContainDriver: 0}).then(res => {
        this.staffOptions = res.data;
      })
    },

    // 提交-表单
    onSubmit() {
      const that = this, U = that.U, fm = that.fm, ps = U.scopy(fm.ps);

      that.$refs[fm.fname].validate(valid => {
        if(!valid){return false;}else{
          // 审核后通知人uname，多个通知逗号拼接，可为空
          ps.alNoticeChoice = ps.alNoticeChoice.join(',');

          orderSer.checkStaffReimburse(ps).then(res => {
            if (res.code !== 1) {
              U.qerror(res.msg);
            }else{
              U.qsuccess(res.msg);

              that.closeMd();
              that.$emit("reloadDg");
            }
          });
        }
      });
    }
  },
};
</script>
